package logic

import (
	"context"
	"meituan-waimai/meituanrpc/meituanrpc"

	"meituan-waimai/api/internal/svc"
	"meituan-waimai/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInfoLogic {
	return &UpdateUserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserInfoLogic) UpdateUserInfo(req *types.UpdateUserInfoRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	info, err := l.svcCtx.MeiTuanRpc.UpdateUserInfo(l.ctx, &meituanrpc.UpdateUserInfoRequest{
		UserId:      req.UserId,
		Account:     req.Account,
		Password:    req.Password,
		HeadImage:   req.HeadImage,
		NikeName:    req.NikeName,
		Mobile:      req.Mobile,
		PayPassword: req.PayPassword,
		SmsCode:     req.SmsCode,
	})
	if err != nil {
		return &types.Response{
			Code: -1,
			Msg:  "信息完善失败",
			Data: err.Error(),
		}, nil
	}
	return &types.Response{
		Code: -1,
		Msg:  "信息完善成功",
		Data: info,
	}, nil
}
